<template>
	<view class="box">
		<view class="top ">
			<view class="bg">
				<u-navbar :is-back="false" title="金点科技"></u-navbar>
			</view>
			<view class="uni-margin-wrap">
				<swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="2000"
					:duration="500">
					<swiper-item v-for="i in swiper" :key="i.id" @click="lookDetail(i.url)">
						<image :src="i.image_format" mode="widthFix"></image>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<!-- 通知 -->
		<view class="pads10 bf df aic box-borred marb20 ">
			<u-notice-bar mode="vertical" :list="text" direction="column" icon="volume-fill" bgColor="#fff"
				@click="goNotice" :more-icon="true" @getMore="getmore"></u-notice-bar>
		</view>
		<!-- 菜单 -->
		<view class="menu_box" v-if="menuList.length>0">
			<view class="item" v-for="(i,index) in menuList" :key="i.id" @click="goShop(i.url)">
				<view class="menu_pic">
					<image :src="i.image_format" mode="widthFix" style="border-radius: 50%;"></image>
				</view>
				<view class="menu_title">
					{{i.title}}
				</view>
			</view>
		</view>
		<!-- 拼团专区 -->
		<view class="ptzq" style="width: 710rpx; margin:0 auto;">
			<image src="https://vw.xcyouguo.com/image/pintuan.png" mode="widthFix"
				style="width: 710rpx; margin-bottom: 10rpx;" @click="goJap('/page/JoinGroup/JoinGroup')"></image>
			<!-- <image src="https://jdkj.cn/image/pintuan.png" mode="widthFix" style="width: 710rpx; margin-bottom: 10rpx;"
				@click="goJap('/page/JoinGroup/JoinGroup')"></image> -->

		</view>
		<!-- 热销 -->
		<view class="hot">
			<view class="desc">
				<span class="icon"></span>
				<text>热销专区</text>
			</view>
			<view class="more" @click="gosearch('more')">
				<text>更多</text>
				<span class="icon"></span>
			</view>
		</view>
		<!-- 展示 商品-->
		<view class="showGoods" v-if="goodsList.length>0">
			<view class="item" v-for="item in goodsList" :key="item.id"
				@click="lookDetail(`/pages/goods-details/goods-details?id=`,item.id)">
				<view class="pic">
					<image :src="item.images_format[0]" mode="widthFix" style="width: 345rpx;"></image>
				</view>
				<view class="ct">

					<view class="name_box">
						<span class="fw4" style="color: #666; font-size: 26rpx;">{{item.name}}</span>
					</view>
					<view class="num_box">
						<span style="color: #FA453C; font-size: 36rpx;">￥{{item.min_price}}</span> <span
							style="color: #999;font-size: 24rpx;">月销 {{item.sale_count}}</span>
					</view>
				</view>
			</view>
		</view>
		<view class="noDAta" v-else>
			<view class="pic">
				<image src="../../static/empty.png" mode="widthFix" style="width: 401rpx; height: 240rpx;"></image>
			</view>
		</view>


		<!-- 版权 -->
		<view class="bq">
			©金点科技版权所有
		</view>
		<view class="tabNav">
			<Tabbar ind="1"></Tabbar>
		</view>
	</view>
</template>

<script>
	import QQMapWX from '@/common/qqmap-wx-jssdk.js';
	// 腾讯地图Api
	const qqMapsdk = new QQMapWX({
		key: 'ZXUBZ-PTG3W-C5ERB-OIVDN-P7PKF-PPFS5' //这里填写自己申请的key
	});
	import {
		// 轮播图
		getCarousels,
		// tab
		getTabList,
		// 推荐
		getGoodListno2,
		// getWaterGoods,
		// 通知
		getTzList,


	} from '@/api/index.js';
	import {
		getAddTeams
	} from '@/api/product.js'
	export default {

		data() {
			return {
				swiper: [
				],
				//通知
				text: ["清仓大甩卖", "一元一件", "假一赔十"],
				// 通知详情
				textList: [],
				//菜单
				menuList: [
				],
				goodsList: [],
				style: {},
				show: true,
				name: "贵阳市",
				latitude: "",
				longitude: "",
				address: ""
			}
		},
		mounted() {

		},
		onLoad(res) {
			this.initData()
			if (res.q) {
				let obj = {
					mid: decodeURIComponent(res.q).split('=')[1]
				}
				console.log("加入",obj.mid);
				uni.setStorageSync("mid",obj.mid)
				this.getAddTeam(obj.mid)
			}else{
				console.log("不加入");
			}
			
		},
		onShow() {
			let mid = uni.getStorageSync('mid')||""
			if(mid){
				this.getAddTeam(mid)
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 170) {
				this.style = {
					background: '#6dc762'
				}
			} else {
				this.style = {
					background: 'transparent'
				}
			}
		},


		methods: {
			
			getAddTeam(id) {
				getAddTeams(id).then(res => {
					if (res.data.code==200) {
						toast("加入团队成功")
					} else {
						toast(res.data.msg)
					}
				})
			},
			// 初始化
			initData() {
				// 轮播图
				getCarousels().then((res) => {
					console.log("轮播图数据", res);
					this.swiper = res.data
				})
				// tab
				getTabList().then((res) => {
					console.log("tab数据", res);
					this.menuList = res.data
	
				})
				// 通知
				getTzList().then((res) => {
					console.log("通知列表数据", res);
					this.textList = res.data
					this.text = res.data.map((item) => {
						return item.title
					})
				})

				// // 商品详情
				getGoodListno2().then((res) => {
					console.log("商品数据", res);
					this.goodsList = res.list
				})
			},
			// 去分类
			goShop(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 指定跳转
			goJap(url) {
				uni.navigateTo({
					url
				})
			},
			// 去商城
			goShops() {
				this.show = false
				uni.switchTab({
					url: '/pages/store/store'
				})
			},
			// 查看详情
			lookDetail(url, id) {
				let urls = ''
				if(id){
					urls = url + id
				}else{
					urls = url
				}
				console.log(urls);
				uni.navigateTo({
					url: urls
				})

			},
			goNotice(index) {
				console.log(index);
				let id = this.textList[index].id
				uni.navigateTo({
					url: '/page/goNotice/goNotice?id=' + id
				})
			},
			getmore() {
				console.log("更多");
			},
			gosearch(type) {
				uni.navigateTo({
					url: '/page/product-list/product-list?type=' + type
				})
			},
			// 获取附近详细
			getAddresslist(latitude, longitude) {

				var th_is = this;
				qqMapsdk.reverseGeocoder({
					location: {
						latitude,
						longitude
					},
					get_poi: 1,
					poi_options: 'policy=1;page_size=20;page_index=1',
					success: res => {
						th_is.address = res.result.pois.length > 0 ? res.result.pois[0] : {};
						console.log(th_is.address);


					},
					fail: err => {
						uni.showToast({
							title: err.message,
							icon: 'none',
							duration: 3000
						})
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.tabNav {
		position: fixed;
		bottom: 0;
	}

	.box {
		background-color: #f5f5f5;
	}

	.top {
		position: relative;
		height: 440rpx;
		margin-bottom: 40rpx;

		.bg {
			image {
				width: 750rpx;
				height: 297rpx;
			}
		}

		.search {
			font-family: Source Han Sans CN;
			display: flex;
			align-items: center;
			margin-top: -20rpx;
			padding: 0 20rpx;

			.dw_icon {
				width: 36rpx;
				height: 36rpx;
				background-image: url('/static/img/dw.png');
				background-size: cover;
				background-repeat: no-repeat;

			}

			.dw_ct {
				font-size: 32rpx;
				font-weight: 400;
				width: 120rpx;
				color: #FFFFFF;
				margin: 0 10rpx;
			}

			.search_ipt {
				width: 380rpx;
				position: relative;
				background-color: rgba(0, 0, 0, 0.1);
				height: 64rpx;
				border-radius: 32rpx;
				overflow: hidden;
				box-sizing: border-box;
				padding: 0 0 0 80rpx;

				input {
					height: 64rpx;
					display: inline-block;
					color: #FFFFFF;
					font-size: 26rpx;
				}

				.icon {
					position: absolute;
					background-image: url('/static/img/ss.png');
					background-size: cover;
					background-repeat: no-repeat;
					width: 28rpx;
					height: 28rpx;
					left: 28rpx;
					top: 23rpx;
				}

			}
		}
	}

	.uni-margin-wrap {
		width: 710rpx;
		position: absolute;
		top: 176rpx;
		left: 20rpx;
		z-index: 2;
	}

	.swiper {
		height: 280rpx;

		image {
			width: 710rpx;
			height: 280rpx;
		}
	}

	//菜单
	.menu_box {
		width: 710rpx;
		padding: 20rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 20rpx auto;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;

		.item {
			margin-top: 20rpx;
			padding: 0 20rpx;

			.menu_pic image {
				width: 90rpx;
				height: 90rpx;
				margin: 10rpx;
			}

			.menu_title {
				text-align: center;
				font-weight: 400;
				color: #333333;
				font-size: 26rpx;
			}
		}

	}

	// 热销
	.hot {
		width: 710rpx;
		height: 100rpx;
		margin: 10rpx auto;
		padding: 0 10rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-family: Source Han Sans CN;

		.desc {
			display: flex;
			align-items: center;
			font-weight: 500;
			color: #333333;

			.icon {
				width: 36rpx;
				height: 36rpx;
				background-image: url("/static/img/rxzq.png");
				background-size: cover;
				background-repeat: no-repeat;
			}
		}

		.more {
			display: flex;
			align-items: center;
			font-weight: 400;
			color: #999999;

			.icon {
				width: 20rpx;
				height: 20rpx;
				background-image: url("/static/img/箭头.png");
				background-size: cover;
				background-repeat: no-repeat;
			}
		}
	}

	.noDAta {
		width: 710rpx;
		margin: 20rpx 20rpx 100rpx 20rpx;

		.pic {
			width: 401rpx;
			height: 240rpx;
			margin: 100rpx auto;
		}
	}

	//商品展示
	.showGoods {
		width: 710rpx;
		margin: 20rpx 20rpx 100rpx 20rpx;
		display: flex;
		justify-content: space-between;
		font-family: Source Han Sans CN;
		flex-wrap: wrap;

		.item {
			width: 345rpx;
			border-radius: 10rpx;
			overflow: hidden;
			margin-top: 40rpx;
			background-color: #ffffff;

			.pic image {
				width: 345rpx;
			}

			.ct .title {
				width: 278rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
				margin: 10rpx;
			}

			.ct .name_box,
			.ct .num_box {
				display: flex;
				justify-content: space-between;
				margin: 10rpx;
				align-items: center;
			}

		}
	}

	.bq {
		height: 200rpx;
		line-height: 100rpx;
		font-weight: 400;
		color: #C2C2C2;
		text-align: center;
		font-size: 26rpx;
	}

	//拒单提示
	.pop {
		width: 610rpx;
		height: 600rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 30rpx 20rpx;
		box-sizing: border-box;
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #333333;
		position: relative;

		.tips {
			line-height: 40rpx;
			text-align: center;
		}

		.serial {
			text-align: center;
			font-size: 32rpx;
			line-height: 50rpx;
			margin-top: 30rpx;

		}

		.reasons {
			width: 560rpx;
			height: 120rpx;
			background: #F5F5F5;
			border: 1px solid #E6E6E6;
			border-radius: 10rpx;
			font-size: 30rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #666666;
			line-height: 40rpx;
			margin: 20rpx auto;
			box-sizing: border-box;
			padding: 10rpx 20rpx;
		}

		.note {
			width: 555rpx;
			height: 97rpx;
			font-size: 26rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FA453C;
			line-height: 40rpx;
			margin: 20rpx auto;
		}

		.btns {
			width: 560rpx;
			height: 80rpx;
			background: #6BC665;
			border-radius: 10rpx;
			text-align: center;
			line-height: 80rpx;
			margin: 40rpx auto;
			color: #fff;
		}

	}
</style>